﻿using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XW.Core
{
    /// <summary>
    /// Http扩展
    /// </summary>
    public static class HttpRequestExtensions
    {
        /// <summary>
        /// 是否为ajax请求
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static bool IsAjaxRequest(this HttpRequest request)
        {
            if (request == null || request.Headers  == null)
            {
                return false;
            }
            if (request.Headers.XRequestedWith == "XMLHttpRequest")
            {
                return true;
            }
            return false;
        }
    }
}
